package com.example.fwcz.controller;

import com.example.fwcz.entity.meetInfo;
import com.example.fwcz.model.vo.Result;
import com.example.fwcz.service.MeetService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class MeetController {
    @Autowired
    MeetService meetService;

    /**
     * 添加会议信息
     * @param meetInfo
     * @return
     */
    @PostMapping("/meetadd")
    public Result addMeet(@RequestBody meetInfo meetInfo){
        meetService.addMeet(meetInfo);
        return Result.ok("添加会议成功");
    }

    /**
     * 删除会议信息
     * @param id
     * @return
     */
    @DeleteMapping("/meetdelete")
    public Result deleteMeet(@RequestParam int id){
        meetService.deleteMeet(id);
        return Result.ok("删除会议成功");
    }

    /**
     * 修改会议信息
     * @param meetInfo
     * @return
     */
    @PutMapping("/meetchange")
    public Result changeMeet(@RequestBody meetInfo meetInfo){
        meetService.changeMeet(meetInfo);
        return Result.ok("修改会议成功");
    }

    /**
     * 根据会议 ID搜索具体某一个会议信息
     * @param id
     * @return
     */
    @GetMapping("/meetone")
    public Result searchOnemeet(@RequestParam int id){
        return Result.ok("请求成功",meetService.searchOnemeet(id));
    }

    /**
     * 根据用户 【用户名】 搜索会议信息
     * @param user_id
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/meetuser")
    public Result searchUsermeet(@RequestParam String user_id,
                                @RequestParam(defaultValue = "1") Integer pageNum,
                                @RequestParam(defaultValue = "10") Integer pageSize){
        String orderBy="create_time desc";
        PageHelper.startPage(pageNum, pageSize, orderBy);
        PageInfo<meetInfo> pageInfo=new PageInfo<>(meetService.searchUsermeet(user_id));
        return Result.ok("请求成功",pageInfo);
    }

    /**
     * 根据房东 【用户名】搜索会议信息
     * @param landlord_id
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/meetlandlord")
    public Result searchLandlordmeet(@RequestParam String landlord_id,
                                @RequestParam(defaultValue = "1") Integer pageNum,
                                @RequestParam(defaultValue = "10") Integer pageSize){
        String orderBy="create_time desc";
        PageHelper.startPage(pageNum, pageSize, orderBy);
        PageInfo<meetInfo> pageInfo=new PageInfo<>(meetService.searchLandlordmeet(landlord_id));
        return Result.ok("请求成功",pageInfo);
    }
}
